package cn.hy.dataSync.task.runner;


import cn.hy.dataSync.job.State;
import cn.hy.dataSync.task.TaskContainer;

/**
 * 线程任务类
 */
public class TaskContainerRunner implements Runnable {

    private TaskContainer taskContainer;

    private State state;

    public TaskContainerRunner(TaskContainer task) {
        this.taskContainer = task;
        this.state = State.SUCCEEDED;
    }

    @Override
    public void run() {
        try {
            Thread.currentThread().setName(
                    String.format("task-%s-%d",
                            this.taskContainer.getJobId(),
                            this.taskContainer.getTaskId()));
            this.taskContainer.start();
            this.state = State.SUCCEEDED;
        } catch (Throwable e) {
            this.state = State.FAILED;
            throw new RuntimeException(e);
        }
    }

    public TaskContainer getTaskContainer() {
        return this.taskContainer;
    }

    public State getState() {
        return this.state;
    }

    public void setState(State state) {
        this.state = state;
    }
}
